package wang.aweb.childcar.websocketserver;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;
import wang.aweb.childcar.websocketserver.WebSocketServerHandler;

public class WebSocketServerChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel channel) throws Exception {
        //channel.pipeline().addLast("encoder",new StringEncoder(CharsetUtil.UTF_8));
        ///channel.pipeline().addLast("decoder",new StringDecoder(CharsetUtil.UTF_8));
//        channel.pipeline().addLast("decoder",new StringDecoder(CharsetUtil.UTF_8));
//        channel.pipeline().addLast("encoder",new StringEncoder(CharsetUtil.UTF_8));
        //channel.pipeline().addLast(new WebSocketServerHandler());
        channel.pipeline().addLast("encoder",new StringEncoder(CharsetUtil.UTF_8));
        //channel.pipeline().addLast("decoder",new StringDecoder(CharsetUtil.UTF_8));
        channel.pipeline().addLast(new HttpServerCodec());
        channel.pipeline().addLast(new HttpObjectAggregator(8192));
        channel.pipeline().addLast(new WebSocketServerProtocolHandler("/","Websocket",true,65536*10));
        channel.pipeline().addLast(new WebSocketServerHandler());
    }
}
